package com.example.wearapplication.home;

import androidx.lifecycle.ViewModelProvider;

import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.GridView;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.example.wearapplication.ImgAdapter;
import com.example.wearapplication.R;

import java.util.ArrayList;
import java.util.List;

public class HomeFragment extends Fragment {

    private HomeViewModel mViewModel;
    private GridView todayMatchList;
    private TextView welcomeUser;
    private TextView weatherText;
    private static final String TAG = "HomeFragment";

    public static HomeFragment newInstance() {
        return new HomeFragment();
    }


    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
                             @Nullable Bundle savedInstanceState) {

        View view = inflater.inflate(R.layout.home_fragment,container,false);
        todayMatchList = view.findViewById(R.id.todayMatchList);
        welcomeUser = view.findViewById(R.id.welcomeUser);
        weatherText = view.findViewById(R.id.weatherText);
        return view;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        mViewModel = new ViewModelProvider(this).get(HomeViewModel.class);
        // TODO: Use the ViewModel


//        String [] list_data = {"Apple","Banana","Orange","Watermelon","Pear","Grape"};
//        ListAdapter adapter = new ArrayAdapter<String>(this.getActivity(),
//                android.R.layout.simple_list_item_1, list_data);
//        todayMatchList.setAdapter(adapter);

        //使用自定义适配器
        todayMatchList.setAdapter(new ImgAdapter(this.getActivity()));//调用ImgAdapter.java
        todayMatchList.setOnItemClickListener(new AdapterView.OnItemClickListener(){//监听事件
            public void onItemClick(AdapterView<?> parent, View view, int position, long id)
            {
                Log.i(TAG, "onItemClick: 衣服"+position);
            }
        });

    }



}